package com.shensi.appCollect.controller;

import com.shensi.appCollect.config.RedisCustomConfig;
import com.shensi.appCollect.enums.WxConsumptionMessageEnum;
import com.shensi.appCollect.pojo.dto.UniversalRedisMessageDto;
import com.shensi.appCollect.service.RedisConsumptionThemeService;
import com.shensi.appCollect.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * redis 订阅发布模式 改成http形式
 */
@RestController
@RequestMapping("/publish")
public class RedisConsumptionThemeController {

    @Autowired
    private RedisConsumptionThemeService redisConsumptionThemeService;

    @PostMapping("/messageUse")
    public ResultData consumerRedisMessage(@RequestBody UniversalRedisMessageDto dto){
        if(RedisCustomConfig.TOPIC_Template_message_push_1.equals(dto.getChannel())){
            redisConsumptionThemeService.couponMessageSubscription(dto.getData(), WxConsumptionMessageEnum.getByValue(dto.getMessageType()));
        }
        if(RedisCustomConfig.TOPIC_REDUCTION_ACTIVITY.equals(dto.getChannel())){
            //参与充值立减活动
            redisConsumptionThemeService.reductionActivityMessageSubscription(dto.getData(),WxConsumptionMessageEnum.getByValue(dto.getMessageType()));
        }
        return ResultData.success();
    }

}
